package cn.edu.sgu.www.mhxysy.controller.children_equipment;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.children_equipment.ChildrenEquipmentDTO;
import cn.edu.sgu.www.mhxysy.entity.children_equipment.ChildrenEquipment;
import cn.edu.sgu.www.mhxysy.pager.children_equipment.ChildrenEquipmentPager;
import cn.edu.sgu.www.mhxysy.restful.JsonPage;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.children_equipment.ChildrenEquipmentService;
import cn.edu.sgu.www.mhxysy.vo.children_equipment.ChildrenEquipmentVO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "子女装备管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/children_equipment", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class ChildrenEquipmentController {

    private final ChildrenEquipmentService childrenEquipmentService;

    public ChildrenEquipmentController(ChildrenEquipmentService childrenEquipmentService) {
        this.childrenEquipmentService = childrenEquipmentService;
    }

    @ApiOperation("穿戴子女装备")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "childrenId", value = "子女ID", required = true),
            @ApiImplicitParam(name = "equipmentId", value = "子女装备ID", required = true)
    })
    @RequestMapping(value = "/wear", method = RequestMethod.POST)
    public JsonResult<Void> wear(
            @NotBlank(message = "子女" + CustomMessages.ID_NOT_NULL) String childrenId,
            @NotBlank(message = CustomMessages.CHONGWU_EQUIPMENT_ID_NOT_NULL) String equipmentId) {
        childrenEquipmentService.wear(childrenId, equipmentId);

        return JsonResult.success(CustomMessages.OPERATE_SUCCESS);
    }

    @ApiOperation("添加子女装备")
    @ApiOperationSupport(ignoreParameters = "id")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public JsonResult<Void> insert(@Validated ChildrenEquipmentDTO chongwuEquipmentDTO) {
        childrenEquipmentService.insert(chongwuEquipmentDTO);

        return JsonResult.success(CustomMessages.INSERT_SUCCESS);
    }

    @ApiOperation("通过ID删除子女装备")
    @RequestMapping(value = "/deleteById", method = RequestMethod.POST)
    public JsonResult<Void> deleteById(
            @ApiParam(name = "id", value = "子女装备ID", required = true)
            @NotBlank(message = CustomMessages.ID_NOT_NULL) String id) {
        childrenEquipmentService.deleteById(id);

        return JsonResult.success(CustomMessages.DELETE_SUCCESS);
    }

    @ApiOperation("通过ID修改子女装备信息")
    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    public JsonResult<Void> updateById(@Validated ChildrenEquipmentDTO chongwuEquipmentDTO) {
        childrenEquipmentService.updateById(chongwuEquipmentDTO);

        return JsonResult.success(CustomMessages.UPDATE_SUCCESS);
    }

    @ApiOperation("查询全部子女装备")
    @RequestMapping(value = "/selectAll", method = RequestMethod.GET)
    public JsonResult<List<ChildrenEquipment>> selectAll() {
        List<ChildrenEquipment> list = childrenEquipmentService.selectAll();

        return JsonResult.success(null, list);
    }

    @ApiOperation("查询子女装备列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "子女装备类型"),
            @ApiImplicitParam(name = "childrenId", value = "子女ID")
    })
    @RequestMapping(value = "/selectList", method = RequestMethod.GET)
    public JsonResult<List<ChildrenEquipment>> selectList(
            @RequestParam(required = false) Integer type,
            @RequestParam(required = false) String childrenId) {
        List<ChildrenEquipment> list = childrenEquipmentService.selectList(type, childrenId);

        return JsonResult.success(null, list);
    }

    @ApiOperation("通过ID查询子女装备信息")
    @RequestMapping(value = "/selectById", method = RequestMethod.GET)
    public JsonResult<ChildrenEquipment> selectById(
            @ApiParam(name = "id", value = "子女装备ID", required = true)
            @NotBlank(message = CustomMessages.ID_NOT_NULL) String id) {
        ChildrenEquipment chongwuEquipment = childrenEquipmentService.selectById(id);

        return JsonResult.success(null, chongwuEquipment);
    }

    @ApiOperation("分页查询宠物装备列表")
    @RequestMapping(value = "/selectByPage", method = RequestMethod.POST)
    public JsonResult<JsonPage<ChildrenEquipment>> selectByPage(ChildrenEquipmentPager pager) {
        Page<ChildrenEquipment> page = childrenEquipmentService.selectByPage(pager);

        return JsonResult.restPage(page);
    }

    @ApiOperation("查询宠物已穿戴的宠物装备")
    @RequestMapping(value = "/getWeardEquipments", method = RequestMethod.GET)
    public JsonResult<List<ChildrenEquipmentVO>> getWeardEquipments(
            @ApiParam(name = "childrenId", value = "子女装备ID", required = true)
            @NotBlank(message = "子女" + CustomMessages.EQUIPMENT_ID_NOT_NULL) String childrenId) {
        List<ChildrenEquipmentVO> list = childrenEquipmentService.getWeardEquipments(childrenId);

        return JsonResult.success(null, list);
    }

}